#include "process.h"

typedef void (*callback_t)(double total, double current);

double total = 1024.0;
double speed = 1.0;

void Download(callback_t cb)
{
	double current = 0;
	while(current <= total)
	{
		//调一次回调函数cd，打印一次进度条
		cb(total, current);
		//下载
		usleep(3000);	//这里模拟下载，每3000us下载1MB，每3000us调用一次FlushProcess()
		current += speed;
	}
	printf("\ndownload %.2lfMB Done\n", total);
}

void Upload(callback_t cb)
{
	double current = 0;
	while(current <= total)
	{
		//调一次回调函数cd，打印一次进度条
		cb(total, current);
		//上传
		usleep(5000);	//这里模拟上传，每5000us上传1MB，每5000us调用一次FlushProcess()
		current += speed;
	}
	printf("\nupload %.2lfMB Done\n", total);
}

int main()
{
	Download(FlushProcess);
	Download(FlushProcess);
	Upload(FlushProcess);	
	return 0;
}
